package com.lemon.smartsafety.view;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 项目名称：workspace
 * 类描述：
 * 创建人：Fargo
 * 创建时间：2016/8/19 9:06
 * 修改人：Fargo
 * 修改时间：2016/8/19 9:06
 * 修改备注：
 */
public class ViewMapSearch extends LinearLayout {

    @Bind(R.id.back)
    TextView back;
    @Bind(R.id.btn_send)
    TextView btnSend;
    @Bind(R.id.txt_search)
    TextView txtSearch;
    @Bind(R.id.edt)
    EditText edt;
    @Bind(R.id.txt_delete)
    TextView txtDelete;
    @Bind(R.id.txt_line)
    TextView txtLine;
    @Bind(R.id.lineAll)
    LinearLayout lineAll;
    @Bind(R.id.lineBack)
    LinearLayout lineBack;

    private View view;

    public ViewMapSearch(Context context) {
        super(context);
        // TODO Auto-generated constructor stub

        initView(context);
    }

    public ViewMapSearch(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub

        initView(context);
    }

    private void initView(Context context) {


        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.view_map_search, this);
        ButterKnife.bind(this, view);


        edt.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {


            }

            @Override
            public void afterTextChanged(Editable s) {
                if (edt.getText().toString().length() != 0) {
                    txtDelete.setVisibility(VISIBLE);
                } else {
                    txtDelete.setVisibility(INVISIBLE);
                }
            }
        });


        txtDelete.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                edt.setText("");
            }
        });


    }


    //Sky--右边按钮单独点击事件
    public interface AllClick {
        void click();
    }


    public void setSendClick(final AllClick allClick) {
        btnSend.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                allClick.click();
            }
        });

    }

    public void setBackClick(final AllClick allClick) {
        lineBack.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                allClick.click();
            }
        });

    }



    /**
     * 设置右按钮的文字
     *
     * @return
     */
    public String getEdtText() {

        return edt.getText().toString().trim();
    }


}
